// pages/person/currency/currency.js
const app = getApp()
Page({
  /**
   * 页面的初始数据
   */
  data: {
    topbar: [{
      id: 0,
      name: '全部'
    }, {
      id: 1,
      name: '收入'
    }, {
      id: 2,
      name: '支出'
    }],
    id:0,//判断收入和支出
    currentTab: 0,
    date: '',
    userinfo:'', //用户信息
    lists:'', //接口返回数据
    list:[],//循环数据
    page:1
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    let that = this
    wx.getStorage({
      key: 'userinfo',
      success: function(res) {
        console.log(res.data)
        that.setData({
          userinfo: res.data
        })
        that.load()
      },
    })
  },


  // 日期选择器
  bindDateChange(e) {
    this.setData({
      date: e.detail.value,
      page:1
    })
    this.load()
  },
  
  // 提现
  jumpcash() {
    wx.navigateTo({
      url: '/pages/person/cash/cash',
    })
  },
  //加载数据
  load() {
    let that = this
    wx.request({
      url: app.globalData.api + "integral",
      data: {
        uid: that.data.userinfo.id,
        status: that.data.id,
        datetime:that.data.date,
        page:that.data.page
      },
      success: function(res) {
         console.log(res)
        if (res.data.list.length == 0 && res.data.code == 0) {
          wx.showToast({
            title: '已经到底了',
          })
        } else {
          that.setData({
            lists: res.data,
            list: that.data.list.concat(res.data.list),
            page: ++that.data.page
          })
        }
      },
    })
  },

  // tab切换
  tabswitch: function(e) {
    var that = this;
    let currentTab = e.currentTarget.dataset.idx
    let id = e.currentTarget.dataset.id
    that.setData({
      currentTab: currentTab,
      id:id,
      page:1
    })
    that.load()
  },
  

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})